#include <iostream>
#include <fstream>
#include <string>
#include "bundle.h"

using namespace std;

// g++ decompress.cc bundle.cpp -o decompress -std=c++11 -lpthread
// decompress 压缩包名 解压后文件名
int main(int argc, char *argv[])
{
    if(argc != 3)
    {
        cout << "参数错误" << endl;
        cout << "使用格式应为：decompress 压缩包名 解压后文件名" << endl;
        return -1;
    }

    string ifile = argv[1];
    string ofile = argv[2];
    ifstream ifs;
    ifs.open(ifile, ios::binary);
    ifs.seekg(0, ios::end);
    size_t fsize = ifs.tellg();
    ifs.seekg(0, ios::beg);
    string com;
    com.resize(fsize);
    ifs.read(&com[0], fsize);
    ifs.close();

    string decom = bundle::unpack(com);
    ofstream ofs;
    ofs.open(ofile, ios::binary);
    ofs.write(&decom[0], decom.size());
    ofs.close();
    return 0;
}